import { Pipe, PipeTransform } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { DefaultLanguageService } from '@services/default-language.service';

@Pipe({ name: 'monthFormat' })
export class MonthFormatPipe implements PipeTransform {
  i18n:any;
  constructor(   
    private defaultLanguageService:DefaultLanguageService,
    private translate: TranslateService
  ){
    let defultLanguage = this.defaultLanguageService.getDefaultLanguage();
    this.translate.setDefaultLang(defultLanguage);
    this.translate.use(defultLanguage);
    this.translate.get('myCredit.transaction_page').subscribe((value)=>{
      this.i18n = value;
    });
  }

    transform(key:any): string {
        let format = '';
        switch (key) {
          case "1":
            format = this.i18n.months[0];
            break;
          case "2":
            format = this.i18n.months[1];
            break;
          case "3":
            format = this.i18n.months[2];
            break;
          case "4":
            format = this.i18n.months[3];
            break;
          case "5":
            format = this.i18n.months[4];
            break;
            case "6":
            format =  this.i18n.months[5];
            break;
            case "7":
            format =  this.i18n.months[6];
            break;
            case "8":
            format = this.i18n.months[7];
            break;
            case "9":
            format = this.i18n.months[8];
            break;
            case "10":
            format = this.i18n.months[9];
            break;
            case "11":
            format = this.i18n.months[10];
            break;
            case "12":
            format = this.i18n.months[11];
            break;
          default:
            break;
        }
       let currentMonth = new Date().getMonth() + 1;
       if(currentMonth == key){
         return this.i18n.current_month;
       }
        return format;
      }
}